import Vue from 'vue'
import Vuex from 'vuex'
var Fly = require('flyio/dist/npm/wx')
var fly = new Fly()
console.log(fly.get)
Vue.use(Vuex)
const state = {
  device: {
    width: 0,
    height: 0
  },
  // 微信返回的信息
  userInfo: {
    avatarUrl: null,
    nickName: null,
    openid: null,
    phone: 0,
    code: ''
  },
  UserLoginInfo: {
    userId: '',
    openId: ''
  },
  examPaper: {
    rightAnswer: [],
    commitAnswer: [],
    paperId: 0,
    collectId: [],
    paperName: '',
    time: '',
    clickArray: []
  },
  ExamResult: {
    grade: 0,
    long_time: '',
    paper_name: '',
    correct_num: ''
  },
  // 强化训练,正式考试,随机测试 记录
  randomRecord: {
    paperName: '',
    paperId: 0,
    detailTime: '',
    time: '',
    score: ''
  },
  formalRecord: {
    paperName: '',
    paperId: 0,
    detailTime: '',
    time: '',
    score: ''
  },
  traning: [
    // {
    //   paperId: 0,
    //   paperName: '试卷一'
    // }
  ],
  currentExam: {
    currentId: 0,
    currentName: ''
  }
}
const mutations = {
  appSetDevice (state, device) {
    state.device = device
  },
  setExamPaper (state, payload) {
    console.log(state)
    if (payload.rightAnswer) {
      state.examPaper.rightAnswer = payload.rightAnswer
    }
    if (payload.commitAnswer) {
      state.examPaper.commitAnswer = payload.commitAnswer
    }
    if (payload.examType) {
      state.examPaper.examType = payload.examType
    }
    if (payload.paperId) {
      state.examPaper.paperId = payload.paperId
    }

    if (payload.collectId) {
      state.examPaper.collectId = payload.collectId
    }
    if (payload.paperName) {
      state.examPaper.paperName = payload.paperName
    }
    if (payload.time) {
      state.examPaper.time = payload.time
    }
    if (payload.clickArray) {
      state.examPaper.clickArray = payload.clickArray
    }
    if (payload.totalNum) {
      state.examPaper.totalNum = payload.totalNum
    }
    if (payload.rightTotal >= 0) {
      state.examPaper.rightTotal = payload.rightTotal
    }
    if (payload.rightAnswerArray) {
      state.examPaper.rightAnswerArray = payload.rightAnswerArray
    }
  },
  setrandomRecord (state, payload) {
    console.log(payload)
    console.log('`````````1')
    console.log(state)
    console.log('`````````2')
    if (payload.paperId >= 0) {
      state.randomRecord.paperId = payload.paperId
    }
    if (payload.paperName) {
      state.randomRecord.paperName = payload.paperName
    }
    if (payload.detailTime) {
      state.randomRecord.detailTime = payload.detailTime
    }
    if (payload.time) {
      state.randomRecord.time = payload.time
    }
    if (payload.score >= 0) {
      state.randomRecord.score = payload.score
    }
    if (payload.finishStatus) {
      state.randomRecord.finishStatus = payload.finishStatus
    }
    if (payload.paperTest) {
      state.randomRecord.paperTest = payload.paperTest
    }
    if (payload.commitAnswer) {
      state.randomRecord.commitAnswer = payload.commitAnswer
    }

    if (payload.rightAnswerArray) {
      state.randomRecord.rightAnswerArray = payload.rightAnswerArray
    }
    // console.log(payload.randomRecord)
    // state.randomRecord.push(payload.randomRecord)
    console.log(state.randomRecord)
  },
  setformalRecord (state, payload) {
    console.log(payload)
    console.log('`````````1')
    console.log(state)
    console.log('`````````2')
    if (payload.paperId >= 0) {
      state.formalRecord.paperId = payload.paperId
    }

    //  paperId: this.examPaperId,
    // paperName: this.examPaper.paperName,
    // time: 36,
    // detailTime: '2012-02-12'
    if (payload.paperName) {
      state.formalRecord.paperName = payload.paperName
    }

    if (payload.detailTime) {
      state.formalRecord.detailTime = payload.detailTime
    }
    if (payload.time) {
      state.formalRecord.time = payload.time
    }
    if (payload.score >= 0) {
      state.formalRecord.score = payload.score
    }
    if (payload.finishStatus) {
      state.formalRecord.finishStatus = payload.finishStatus
    }
    if (payload.paperTest) {
      state.formalRecord.paperTest = payload.paperTest
    }
    if (payload.commitAnswer) {
      state.formalRecord.commitAnswer = payload.commitAnswer
    }

    if (payload.rightAnswerArray) {
      state.formalRecord.rightAnswerArray = payload.rightAnswerArray
    }
    // console.log(payload.randomRecord)
    // state.randomRecord.push(payload.randomRecord)
    console.log(state.formalRecord)
  },
  setUserLoginInfo (state, payload) {
    state.LoginInfo.openId = payload.openId
    state.LoginInfo.userId = payload.userId
  },
  initSet (state, payload) {
    console.log(state, payload)
  },
  // 设置考场信息
  setExamSubject (state, payload) {
    console.log(payload)
    state.currentExam.currentId = payload.currentId
    state.currentExam.currentName = payload.currentName
    state.currentExam.roomIndex = payload.roomIndex
  },
  setExamResult (state, payload) {
    state.ExamResult.grade = payload.grade
    state.ExamResult.correct_num = payload.correct_num
    state.ExamResult.paper_name = payload.paper_name
    state.ExamResult.long_time = payload.long_time
  },
  setUserInfo (state, payload) {
    if (payload.openid) {
      state.userInfo.openid = payload.openid
    }
    if (payload.avatarUrl) {
      state.userInfo.avatarUrl = payload.avatarUrl
    }

    if (payload.phone) {
      state.userInfo.phone = payload.phone
    }
    if (payload.nickName) {
      state.userInfo.nickName = payload.nickName
    }
    if (payload.code) {
      state.userInfo.code = payload.code
    }
    if (payload.user) {

    }
  }
  // paperInit (state, payload) {
  //   state.
  // }
}
let actions = {
  async initParamss (context) {
    console.log(context)
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions
})
